using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Mapping.Attributes;
using Lib;

namespace Persistance.Model
{


    ///<summary>
    /// User Object Specification
    ///
    /// UserID (int) --> The unique ID associated with this user.
    /// FullName (varchar) --> The Fullname of the user. Decided to store this for convenience sake.
    /// SecurityLevel (int) --> A number between 1 and 30 to denote the users security clearance. Left a lot of room in case different user types are added in the future.
    ///</summary>

    [Serializable]
    [Class(Lazy = true)]
    public class Items
    {
        #region " Mapping "

        /// <summary>
        /// This is needed for NH. NH only accepts numeric primary keys
        /// </summary>
        private int _itemID;
        //NHIBER: Setts the primary key to ID
        [Id(Name = "ItemID")]
        [Generator(1, Class = "native")]
        public virtual int ItemID
        {
            get { return _itemID; }
            set { _itemID = value; }
        }

        private string _title;
        [Property(Length = 1000)]
        public virtual string Title
        {
            get { return _title ; }
            set { _title = value; }
        }

        private string _description;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        private string _url;
        [Property(Length = 500)]
        public virtual string Url
        {
            get { return _url; }
            set { _url = value; }
        }

        private DateTime _expirationDate;
        [Property(Type = "DateTime")]
        public virtual DateTime ExpirationDate
        {
            get { return _expirationDate; }
            set { _expirationDate = value; }
        }

        private DateTime _dateCreated;
        [Property(Type = "DateTime")]
        public virtual DateTime DateCreated
        {
            get { return _dateCreated; }
            set { _dateCreated = value; }
        }

        private DateTime _dateClaimed;
        [Property(Type = "DateTime")]
        public virtual DateTime DateClaimed
        {
            get { return _dateClaimed; }
            set { _dateClaimed = value; }
        }

        private int _numViews;
        [Property(Type = "int")]
        public virtual int NumViews
        {
            get { return _numViews; }
            set { _numViews = value; }
        }

        private int _numResponses;
        [Property(Type = "int")]
        public virtual int NumResponses
        {
            get { return _numResponses; }
            set { _numResponses = value; }
        }

        private ItemType _itemType;
        [ManyToOne(Column = "ItemTypeID", Cascade = CascadeStyle.All, ForeignKey = "ItemToItemType")]
        public virtual ItemType ItemType
        {
            get { return _itemType; }
            set { _itemType = value; }
        }

        private IList<Photos> _photos = new List<Photos>();
        [Bag(1, Inverse = true)]
        [Key(2, Column = "PhotoID", ForeignKey = "ItemToPhotos")]
        [OneToMany(3, ClassType = typeof(Photos))]
        public virtual IList<Photos> Photos
        {
            get { return _photos; }
            set { _photos = value; }
        }

        #endregion

        ///<summary>
        ///Holds the member of each item
        ///</summary>
        private Users _owner;
        [ManyToOne(Column = "UserID", Cascade = CascadeStyle.All, ForeignKey = "ItemToUserType")]
        public virtual Users Owner
        {
            get { return _owner; }
            set { _owner = value; }
        }

        ///<summary>
        ///Holds the category of each item
        ///</summary>
        private Categories _category = new Categories();
        [ManyToOne(Column = "CategoryID", Cascade = CascadeStyle.All, ForeignKey = "ItemToCategories")]
        public virtual Categories Category
        {
            get { return _category; }
            set { _category = value; }
        }

        //location and status
        ///<summary>
        ///Holds the member of each item
        ///</summary>
        private Locations _location = new Locations();
        [ManyToOne(Column = "LocationID", Cascade = CascadeStyle.All, ForeignKey = "ItemToLocation")]
        public virtual Locations Location
        {
            get { return _location; }
            set { _location = value; }
        }

        private Status _status;
        [OneToOne(ClassType = typeof(Status))]
        public virtual Status Status
        {
            get { return _status; }
            set { _status = value; }
        }

        private Requests _request;
        [OneToOne(ClassType = typeof(Status))]
        public virtual Requests Requests
        {
            get { return _request; }
            set { _request = value; }
        }
       
    }

}
